package com.hb.podao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import com.core.BaseHibernateDAO;

/**
 * Data access object (DAO) for domain model class HbInvoice.
 * 
 * @see com.hb.podao.HbInvoice
 * @author MyEclipse Persistence Tools
 */

public class HbInvoiceDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(HbInvoiceDAO.class);

	// property constants
	public static final String USERID = "userid";

	public static final String NEEDID = "needid";

	public static final String TITLE = "title";

	public static final String DOCUMENTTYPE = "documenttype";

	public static final String DOCUMENTNO = "documentno";

	public static final String ADDRESS = "address";

	public static final String ZIPCODE = "zipcode";

	public static final String MOBILE = "mobile";

	public static final String AMOUNT = "amount";

	public static final String CONSIGNMENTNO = "consignmentno";

	public static final String STATUS = "status";

	public void save(HbInvoice transientInstance) {
		log.debug("saving HbInvoice instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(HbInvoice persistentInstance) {
		log.debug("deleting HbInvoice instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public HbInvoice findById(java.lang.Integer id) {
		log.debug("getting HbInvoice instance with id: " + id);
		try {
			HbInvoice instance = (HbInvoice) getSession().get(
					"com.hb.podao.HbInvoice", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(HbInvoice instance) {
		log.debug("finding HbInvoice instance by example");
		try {
			List results = getSession()
					.createCriteria("com.hb.podao.HbInvoice").add(
							Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding HbInvoice instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from HbInvoice as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByNeedid(Object needid) {
		return findByProperty(NEEDID, needid);
	}

	public List findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}

	public List findByDocumenttype(Object documenttype) {
		return findByProperty(DOCUMENTTYPE, documenttype);
	}

	public List findByDocumentno(Object documentno) {
		return findByProperty(DOCUMENTNO, documentno);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByZipcode(Object zipcode) {
		return findByProperty(ZIPCODE, zipcode);
	}

	public List findByMobile(Object mobile) {
		return findByProperty(MOBILE, mobile);
	}

	public List findByAmount(Object amount) {
		return findByProperty(AMOUNT, amount);
	}

	public List findByConsignmentno(Object consignmentno) {
		return findByProperty(CONSIGNMENTNO, consignmentno);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findAll() {
		log.debug("finding all HbInvoice instances");
		try {
			String queryString = "from HbInvoice";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public HbInvoice merge(HbInvoice detachedInstance) {
		log.debug("merging HbInvoice instance");
		try {
			HbInvoice result = (HbInvoice) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(HbInvoice instance) {
		log.debug("attaching dirty HbInvoice instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(HbInvoice instance) {
		log.debug("attaching clean HbInvoice instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}